<!-- 这个模块我正在开发 我是qq是1966908862   -->
<template>
	<view class="login">
		<view class="text-center">
			<image class="titleImg" src="/static/login_log.png" mode="widthFix"></image>
		</view>
		<form class="form" @submit="formSubmit" @reset="formReset">
			<input class="formItem" name="text" placeholder="输入帐号" />
			<input class="formItem" password="true" name="password" placeholder="输入密码" />
			<!-- 提交按钮 -->
			<button class="formItem submit" form-type="submit">登 陆</button>
		</form>
	</view>
</template>

<script>
// 初始化 uniCloud
import app from '@/common/app.js';
export default {
	methods: {
		// 提交事件
		formSubmit(e) {
			var formdata = e.detail.value;

			if (!formdata.text) {
				uni.showToast({
					title: '用户名不能为空',
					icon: 'none'
				});
			} else if (!formdata.password) {
				uni.showToast({
					title: '密码名不能为空',
					icon: 'none'
				});
			} else {
				// uni.showLoading({
				// 	title: '登录中......',
				// 	mask: true
				// });
				app.callFunction('login_api',
					{
						name: formdata.text,
						password: formdata.password
					},(e) => {
						// uni.hideLoading();
						console.log('成功61:', e);
						uni.showToast({
							title: e.msg,
							icon:'none'
						});
						if(e.state){
							const user_info = e.user_info; //保存下用户数据
							new Promise((resolve, reject) => {
								uni.setStorage({
									key: 'user_info',
									data: user_info,
									success: ()=>{
										console.log('已经缓存，userInfo:', user_info);
										resolve('success')
									}
								});
							}).then(e=>{
								//uni.navigateTo({url:'../demo/demo'})
								uni.switchTab({
									url:'../disinfect/list/list'
								})
								if (user_info.role == '10') {
									//如果是管理员
								}else{
									//如果是工作人员
								}
							})
						}
					}
				);
			}
		}
	}
};
</script>

<style lang="less" scoped>
.login {
	.text-center {
		text-align: center;
	}
	.titleImg {
		height: auto;
		width: 426rpx;
		margin-top: 60rpx;
	}
	.form {
		padding: 60rpx;
		display: block;
		.formItem {
			box-sizing: border-box;
			width: 100%;
			height: 112rpx;
			background-color: #f9f9f9;
			font-size: 36rpx;
			padding: 32rpx;
			margin: 20rpx 0;
			border-radius: 56rpx;
			&.submit {
				background-color: #6dddcb;
				color: #ffffff;
				text-align: center;
				font-size: 40rpx;
				line-height: 40rpx;
			}
		}
	}
}
</style>
